(function ($) {


    function mytabsinit(srcelement) {


        this.mydefault = {

            srctargetele: $(srcelement),
            tabSelector: "Tabs",
            tabTarget: "myTarget",
            activeClass: "btn-success"

        };


        return this;

    }

    $.fn.mytabs = function (option) {

        if (typeof (option) != "undefined" & this.data("mytabs")) {

            var mytabinst = this.data("mytabs");

            if (mytabinst) {
                if ($.isFunction(mytabinst[option])) {
                    return mytabinst[option].apply(mytabinst, Array.prototype.slice.call(arguments, 1));
                }

            }
        }
        else {
            if (option) {

                $.extend(option, { srctarget: this });
            }


            var data = this.data("mytabs");
            if (!data) {
                this.data("mytabs", new mytabsinit(this))


                this.data("mytabs").setdefault(option);

                this.data("mytabs").attachPlugin();

            }
            return this;
        }

    };
    $.extend(mytabsinit.prototype, {
        attachPlugin: function () {

            var that = this;
            this.mydefault.srctargetele.find(this.mydefault.tabSelector).bind("click", function () {
                if (that.mydefault.srctargetele.find(that.mydefault.tabSelector).hasClass(that.mydefault.activeClass)) {
                    that.mydefault.srctargetele.find(that.mydefault.tabSelector).removeClass(that.mydefault.activeClass);
                   
                }

                $(this).addClass(that.mydefault.activeClass);
                $($(this).attr(that.mydefault.tabTarget)).siblings().hide();
                $($(this).attr(that.mydefault.tabTarget)).show();

            });
            var selectedTabHeader = this.mydefault.srctargetele.find(this.mydefault.tabSelector).filter(function () {

                return $(this).hasClass(that.mydefault.activeClass);
            })
            if (selectedTabHeader.length == 1) {

                selectedTabHeader.trigger("click");
            } else {
                this.mydefault.srctargetele.find(this.mydefault.tabSelector).first().trigger("click");

            }
            return this;

        },

        setdefault: function (opt) {

            $.extend(true, this.mydefault, opt);

            // alert(this.default.srctarget.length);
        }
    })
    ;

    $.fn.mytabs.constructor = mytabsinit;

})
(jQuery);
/**
 * Created by wangcb on 2015/3/4.
 */
/**
 * Created by wangcb on 2015/3/5.
 */
/**
 * Created by wangcb on 2015/3/28.
 */
/**
 * Created by wangcb on 2015/3/30.
 */
